// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        id:{
            default: 0,
            type: cc.Integer
        },
        num:{
            default: 0,
            type: cc.Integer
        },
        color:{
            default: 0,
            type: cc.Integer
        },
        cardSel:{
            default: [],
            type: [cc.SpriteFrame]
        },
        select:{
            default: false,
            type: cc.Boolean
        }
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.node.on(cc.Node.EventType.TOUCH_START,this.touch,this);
        this.node.on(cc.Node.EventType.TOUCH_MOVE,this.touchMove,this);
        this.node.on(cc.Node.EventType.TOUCH_END,this.touchEnd,this);
    },

    // update (dt) {},

    touch(event){
        cc.log('触摸事件开始',this.num,this.color);
        if(!this.select){
            this.node.getComponent(cc.Sprite).spriteFrame = this.cardSel[1];
            this.select = true;
        }
        else{
            this.node.getComponent(cc.Sprite).spriteFrame = this.cardSel[0];
            this.select = false;
        }
        
        event.stopPropagation();
    },
    touchMove(event){
        event.stopPropagation();
    },
    touchEnd(event){
        event.stopPropagation();
    }
});
